import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

// 静态路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-home' }
    }],
  },
  {
    path: '/calculator',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Calculator',
        component: () => import('@/views/calculator/index'),
        meta: { title: '计算器', icon: 'el-icon-s-home' }
      }
    ],
  },
  {
    path: '/system/notice/info',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':id(\\d+)',
        component: () => import('@/views/system/notice/info/index'),
        name: 'NoticeInfo',
        meta: { title: '详情', activeMenu: '/system/notice' }
      }
    ]
  },
  {
    path: '/systemtool/gen/save',
    component: Layout,
    hidden: true,
    meta: { title: '代码生成' },
    children: [
      {
        path: 'import',
        component: () => import('@/views/systemtool/gen/import-and-save/index'),
        name: 'ImportGen',
        meta: { title: '导入', activeMenu: '/systemtool/gen' }
      },
      {
        path: ':id(\\d+)',
        component: () => import('@/views/systemtool/gen/edit-and-save/index'),
        name: 'EditGen',
        meta: { title: '编辑', activeMenu: '/systemtool/gen' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
